package com.yupi.generator;

import com.yupi.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * 静态文件生成和动态文件生成结合
 */
public class MainGenerator {

    public static void Generate(MainTemplateConfig dataModel) throws TemplateException, IOException {
        //1、静态文件生成
        //获取整个项目的根目录
        String rootPath = System.getProperty("user.dir");
        File rootFile = new File(rootPath);
        System.out.println("root：" + rootPath);
        //输入路径
        String inputPath = new File(rootFile,"hezi-generator-demo-projects/acm-template").getAbsolutePath();
        //String inputPath = rootPath + File.separator + "hezi-generator-demo-projects" + File.separator + "acm-template";
        //输出路径
        String outputPath = rootPath;
        //拷贝文件
        StaticGenerator.copyFilesByRecursive(inputPath,outputPath);



        //2、动态文件生成
        //指定模板文件的路径
        String projectPath = System.getProperty("user.dir") + File.separator + "hezi-generator-basic";
        System.out.println(projectPath);
        File parentFile = new File(projectPath);
        File file = new File(parentFile,"src/main/resources/templates/MainTemplate.java.ftl");
        String dynamicInputPath = file.getPath();
        String dynamicOutputPath = rootPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java";

        DynamicGenerator.doGenerate(dynamicInputPath, dynamicOutputPath, dataModel);
    }
}
